const path = require("path");
const { VueLoaderPlugin } = require("vue-loader");
const HtmlWebpackPlugin = require("html-webpack-plugin");

module.exports = {
  // 1. 入口 entry
  entry: "./src/main.js",
  // 2. 输出 output
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].[contenthash:8].js",
  },
  // 3. 加载器 loader
  module: {
    rules: [
      {
        test: /\.css$/, // 处理 .css 结尾的文件
        use: [
          // 从右往左依次执行
          "vue-style-loader",
          {
            loader: "css-loader",
            options: {},
          },
        ],
      },
      {
        test: /\.less$/,
        use: [
          // 从右往左依次执行
          "vue-style-loader",
          {
            loader: "css-loader",
            options: {},
          },
          "less-loader",
        ],
      },
      {
        test: /\.s[ac]ss$/,
        use: [
          // 从右往左依次执行
          "vue-style-loader",
          {
            loader: "css-loader",
            options: {},
          },
          "sass-loader",
        ],
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
    ],
  },
  // 4. 插件 plugin
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      // 以 index.html 为模板创建新的html文件，新文件会自动引入打包生成的资源
      template: path.resolve(__dirname, "public/index.html"),
    }),
  ],
  // 5. 模式 mode
  // mode: 'development',
  mode: "production",

  devServer: {
    port: 3000,
    host: 'localhost',
    open: true,
    hot: true,
  },

  devtool: 'source-map'
};
